<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2018 http://www.donglixia.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: 十万马 <962863675@qq.com>
// +----------------------------------------------------------------------
// | DateTime: 2018-02-09 16:17
// +----------------------------------------------------------------------

namespace app\index\controller;

use app\index\model\Article;
use think\Request;

class Activity extends Base
{
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->currentModel = new Article();//实例化当前模型
    }

    /**
     * 活动中心
     * @return mixed
     */
    public function index()
    {
        $param = $this->request->param();
        $cat_ids = $this->currentModel->getCatIdByCatType(['cat_type'=>206]);//类型：活动中心cat_id 集
        $curr_cat_id = !empty($param['cat_id']) ? $param['cat_id'] : 5;//当前cat_id
        $this->assign('curr_cat_id', $curr_cat_id);

        //获取数据列表
        $dataList = $this->currentModel->getDataList(['cat_id'=> $curr_cat_id]);
        $this->assign('dataList', $dataList);

        //获取显示位置为"顶部"的分类数据
        $map = [];
        $map['location'] = 201;
        $map['cat_id'] = ['in', $cat_ids];
        $topList = $this->currentModel->getLocationTree($map);
        $this->assign('topList', $topList);

        //获取显示位置为"左侧"的分类数据
        $map = [];
        $map['location'] = 202;
        $map['cat_id'] = ['in', $cat_ids];
        $leftList = $this->currentModel->getLocationTree($map);
        $this->assign('leftList', $leftList);

        //获取banner
        $banner = $this->currentModel->getBanner('banner', 'AC');
        $this->assign('banner', $banner);

        $this->assign('web', ['title' => '活动中心']);//网站标题
        return $this->fetch();
    }

    /**
     * 活动详情
     * @return mixed
     */
    public function detail()
    {
        $param = $this->request->param();
        $id = !empty($param['id']) ? $param['id'] : 0;
        $data = $this->currentModel->getArticleInfo(['art_id'=>$id]);
        $this->assign('data', $data);
        if (empty($data)) {
            return $this->fetch(STATIC_PATH.'/404.html');
        }

        //获取最近活动列表
        $cat_ids = $this->currentModel->getCatIdByCatType(['cat_type'=>206]);//类型：活动中心
        $latestList = $this->currentModel->getLatestNews(['cat_id'=>['in', $cat_ids]]);
        $this->assign('latestList', $latestList);

        $this->assign('web', ['title' => $data['title']]);//网站标题
        return $this->fetch();
    }



}

